﻿/**
* @author maze | guavestudios.com
* @license MIT License see LICENSE.TXT
* @version 0.1
*/

package com.guavestudios.fcon.plugins {
	import com.guavestudios.fcon.api.IControlableConsole;

	public class AutoStartPlugin implements IConsolePlugin{
		
		private var console:IControlableConsole;
		public function AutoStartPlugin() {
			
		}
		
		//{ PUBLIC METHODS
		
		/**
		* Execute the autostart MANUALLY!!!
		*/
		public function executeAutostart():void
		{
			startup();
		}
		//functions for interface
		/**
		* Called when the plugin is finally loaded
		* @param	c
		*/
		public function initPlugin(c:IControlableConsole):void
		{
			console=c;
			
			
		}
		/**
		* Request the unload for the plugin
		*/
		public function unloadPlugin():void
		{
			console=null;
		}
		/**
		* Current state of the plugin see @see com.guavestudios.fcon.plugins.PluginState
		*/
		public function get State():int
		{
			return 0;
		}
		/**
		* Plugin name
		*/
		public function get Name():String
		{
			return "AutoStart";
		}
		/**
		* Plugin version
		*/
		public function get Version():String
		{
			return "r1";
		}
		//}
		
		//{ PRIVATE FUNCTIONS
		private function startup():void
		{
			var c:XML=console.getConfig("AutoStart.commands");
			
			if (c)
			{
				if (c.length()>0)
				{
					var childs:XMLList=c.children();
					for each (var cc:XML in childs)
					{
						console.execute(cc.toString());
					}
				}
			}
		}
		//
	}
	
}
